﻿Imports System.Threading
Imports System.Drawing.Drawing2D
Imports System.IO
Imports System.Net

Public Class Betafrm
    Public Shared fconfig As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\MMusic\Config.ini"
    Public Shared MP3 As AudioFile
    Public Shared _AutoPlay As Boolean = True
    Private Shared STATUS As String = ""
    Public Shared f As MFile

    Public Shared url As String = ""
    Public Shared alenght As Integer = 0
    Public Shared aname As String
    Public Shared _Repeat As Integer = 0
    Dim _Volume As Integer = 0

    Dim s_music As Boolean = False
    Public Shared s_add_favourite As Boolean = True
    Dim s_more As Boolean = False
    Public Shared s_update_ini As Boolean = True
    Dim s_booltooltip As Boolean = False
    Dim link_timkiem As String
    Dim l_trangthai_close As Integer = 0
    Dim link_result As String
    Public Shared numberpage_result As Integer
    Public Shared indexpage_result As Integer
    Public Shared s_loadmorelist As Boolean = False
    Private s_dontloadavatar As Boolean = False
    Public Shared tabpriate As Integer = -1

    Private s_baoloi As Integer = 0
    Private DaNgheindex As Integer = -1
    Public Shared _FolderSave As String = ""

    Public Shared MYLIST As New DataTable
    Public Shared RESULT As New DataTable
    Public Shared BXH As New DataTable
    Public Shared BXH2 As New DataTable
    Public Shared RADI As New DataTable
    Public Shared RELOAD_F As Boolean = False
    Public Shared LinkWeb As String = ""
    Public Shared INDEX_PLAY As Integer = -1
    Public Shared TABPLAY As Integer = -1
    Public Shared ReloadList As Integer = 0
    Public Shared sourceAutoComL As New AutoCompleteStringCollection()

    ' GIAO DIỆN FORM KHỞI TẠO
    ' ----------------------------------------------------------------------------'


    'CÁC THÔNG SỐ MẶC ĐỊNH
    Private Sub Betafrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Seed_m_suft.Width = 0 'Seed màu xanh mặc định là 0
        'Height = 182 'Mặc định chiều cao của form
        btNext.Visible = False  'Ẩn nút NEXT | PREV
        btPrev.Visible = False

        Dim file As New FileInfo(fconfig)
        If Not file.Exists Then
            Dim folder As New DirectoryInfo(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\MMusic\")
            folder.Create()
            Dim ini As New IniFile(fconfig)
            ini.WriteValue("PATH", "SaveFolder", "")
            ini.WriteValue("PATH", "Repeat", "1")
            ini.WriteValue("PATH", "AutoPlay", "True")
            ini.WriteValue("LIKE", "Total", "0")
            _Repeat = 1
        Else
            Dim ini As New IniFile(fconfig)
            If ini.ReadValue("LIKE", "Total") = "" Then
                ini.WriteValue("LIKE", "Total", "0")
            End If
            If ini.ReadValue("PATH", "Volume") = "" Then
                ini.WriteValue("PATH", "Volume", "1000")
            End If
            If ini.ReadValue("PATH", "AutoPlay") = "" Then
                ini.WriteValue("PATH", "AutoPlay", "True")
            End If
            If ini.ReadValue("PATH", "Repeat") = "True" Then
                ini.WriteValue("PATH", "Repeat", "1")
            End If
            If ini.ReadValue("PATH", "SaveFolder") = "" Then
                ini.WriteValue("PATH", "SaveFolder", "")
            End If
            _Repeat = Integer.Parse(ini.ReadValue("PATH", "Repeat"))
            _Volume = Integer.Parse(ini.ReadValue("PATH", "Volume"))
            _AutoPlay = Boolean.Parse(ini.ReadValue("PATH", "AutoPlay"))
            _FolderSave = ini.ReadValue("PATH", "SaveFolder")
        End If
        HIENTHI()

        MYLIST.Columns.Add("Link")
        MYLIST.Columns.Add("Ten")
        RESULT.Columns.Add("Link")
        RESULT.Columns.Add("Ten")
        BXH.Columns.Add("Link")
        BXH.Columns.Add("Ten")
        BXH2.Columns.Add("Link")
        BXH2.Columns.Add("Ten")
        RADI.Columns.Add("Link")
        RADI.Columns.Add("Ten")
        s_dontloadavatar = True
        Load_DSDaNghe()
        s_dontloadavatar = False
        txtSearch.AutoCompleteCustomSource = sourceAutoComL
        If RESULT.Rows.Count = 0 Then
            If MYLIST.Rows.Count = 0 Then
                ButtonA3_Click(sender, e)
            Else
                ButtonA2_Click(sender, e)
            End If
        End If
    End Sub

    Private Sub HIENTHI()

        Select Case _Repeat
            Case 0
                LRepeat.Text = "0 "
            Case 1
                LRepeat.Text = "1 "
            Case 2
                LRepeat.Text = "A "
                btPrev.Visible = True
                btNext.Visible = True
            Case 3
                LRepeat.Text = "S "
                btPrev.Visible = True
                btNext.Visible = True
        End Select
        Volume_suft.Width = (Volume_under.Width - 10) / 1000 * _Volume
        Select Case _AutoPlay
            Case True
                LAutoPlay.Text = "Y "
            Case False
                LAutoPlay.Text = "N "
        End Select
    End Sub

    'Đường viền ngoài cùng
    Private Sub Betafrm_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
        Dim w_pen As Single = 3
        Dim p As New Pen(Color.FromArgb(51, 51, 51), w_pen)
        Dim p2 As New Pen(Color.FromArgb(34, 34, 34), 1)
        Dim p3 As New Pen(Color.FromArgb(34, 34, 34), 2)
        e.Graphics.DrawRectangle(p, New Rectangle(1, 1, Width - w_pen, Height - w_pen))
        e.Graphics.DrawRectangle(p2, New Rectangle(10, 10, 104, 104))
        e.Graphics.DrawLine(p3, 10, 130, 550, 130)
        SetStyle(ControlStyles.UserPaint, True)
        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        SetStyle(ControlStyles.SupportsTransparentBackColor, True)
        Me.BackColor = Color.LimeGreen
        Me.TransparencyKey = BackColor
    End Sub

    'Đổ bóng form
    Private Const CS_DROPSHADOW As Integer = 131072
    Protected Overrides ReadOnly Property CreateParams As System.Windows.Forms.CreateParams
        Get
            Dim cp As CreateParams = MyBase.CreateParams
            cp.ClassStyle = cp.ClassStyle Or CS_DROPSHADOW
            Return cp
        End Get
    End Property

    'Di duyển form
    Private MouseIsDown As Boolean = False
    Private MouseIsDownLoc As Point = Nothing
    Private Sub Betafrm_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove, pbLogo.MouseMove, txtTilte.MouseMove
        If e.Button = MouseButtons.Left Then
            If MouseIsDown = False Then
                MouseIsDown = True
                MouseIsDownLoc = New Point(e.X, e.Y)
            End If
            Me.Location = New Point(Me.Location.X + e.X - MouseIsDownLoc.X, Me.Location.Y + e.Y - MouseIsDownLoc.Y)
            txtLoading.Text = "MOVING..."
            Application.DoEvents()
        End If
    End Sub
    Private Sub Betafrm_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseUp, pbLogo.MouseUp, txtTilte.MouseUp
        MouseIsDown = False
        txtLoading.Text = "..."
    End Sub





    ' CÁC HIỆU ỨNG
    ' ----------------------------------------------------------------------------'

    'Thanh Seed_M
    Private Sub Seed_m_under_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Seed_m_under.MouseClick
        If s_music = False Then Return
        If Not MP3 Is Nothing Then
            'If alenght < 5 And MP3.Status.Trim = "playing" Then
            '    l_ThongBao.Text = "Từ từ, đang tải nhạc mà cưng, click ghê thế!"
            '    PWN.Visible = True
            '    s_baoloi = 0
            '    Application.DoEvents()
            '    Return
            'End If
            If MP3.Status.Trim = "playing" Then
                Dim st As Integer = 10
                Dim w_old As Integer = Seed_m_suft.Width
                Dim w_new As Integer = e.X
                If w_old < w_new Then
                    For i As Integer = w_old + st To e.X Step st
                        Seed_m_suft.Width = i
                        Thread.Sleep(10)
                        Application.DoEvents()
                    Next
                Else
                    For i As Integer = w_old - st To e.X Step -st
                        Seed_m_suft.Width = i
                        Thread.Sleep(10)
                        Application.DoEvents()
                    Next
                End If
                Seed_m_suft.Width = e.X
                Dim tinh As Integer
                tinh = w_new / Seed_m_under.Width * MP3.Milleseconds
                MP3.Seek(tinh * 1000, _Repeat)
                txtSeed_suft.Text = Int(tinh / 60).ToString.PadLeft(2, "0") + ":" + (tinh Mod 60).ToString.PadLeft(2, "0")
            End If
        End If

    End Sub

    Private Sub Seed_m_suft_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Seed_m_suft.MouseClick
        Seed_m_under_MouseClick(sender, e)
    End Sub

    Private Sub Volume_under_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Volume_under.MouseClick
        Volume_suft.Width = e.X - 10
        _Volume = Volume_suft.Width / (Volume_under.Width - 10) * 1000
        If Not MP3 Is Nothing Then
            MP3.MasterVolume = _Volume
        End If
        Dim ini As New IniFile(fconfig)
        ini.WriteValue("PATH", "Volume", _Volume.ToString)
        ToolTipNhac.SetToolTip(Volume_under, "Âm thanh: " + (_Volume / 10).ToString)
        ToolTipNhac.SetToolTip(Volume_suft, "Âm thanh: " + (_Volume / 10).ToString)
    End Sub

    Private Sub Volume_suft_MouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Volume_suft.MouseClick
        Volume_under_MouseClick(sender, e)
    End Sub


    ' CHƯƠNG TRÌNH
    ' ----------------------------------------------------------------------------' 
    Private Sub txtSearch_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSearch.KeyDown
        If txtSearch.Text.IndexOf("Tên bài hát hoặc ca sĩ") > -1 And e.KeyCode <> Keys.Back Then
            txtSearch.Text = txtSearch.Text.Substring(0, txtSearch.Text.IndexOf("Tên bài hát hoặc ca sĩ"))
        ElseIf txtSearch.Text.Length < 2 And e.KeyCode = Keys.Back Then
            txtSearch.Text = "Tên bài hát hoặc ca sĩ"
            txtSearch.Select(0, 0)
        ElseIf e.KeyCode = Keys.Enter Then
            l_Search_Click(e, New EventArgs())
        End If
    End Sub

    Private Sub txtSearch_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Enter
        txtSearch.Select(0, 0)
    End Sub

    Private Sub txtSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.Click
        If txtSearch.Text = "Tên bài hát hoặc ca sĩ" Then
            txtSearch.Select(0, 0)
        End If
    End Sub

    Private Sub l_Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles l_Search.Click
        If txtSearch.Text = "Tên bài hát hoặc ca sĩ" Then
            Return
        End If
        Dim link_search As String = "http://mp3.zing.vn/tim-kiem/bai-hat.html?q=" + txtSearch.Text.Replace(" ", "+")
        SEARCH_ONE(link_search)
        sourceAutoComL.Add(txtSearch.Text)
    End Sub

    Private Sub SEARCH_ONE(ByVal l_search As String)
        Dim page As String = READ_WEB(l_search)
        If page.IndexOf("<div class=""first-search-song"">") < 0 Then
            MessageBox.Show("Không tìm thấy bài hát nào theo từ khóa của bạn :(" + Environment.NewLine + _
                "Hãy thử tìm kiếm với từ khóa ngắn hơn!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        End If

        'Có bài hát

        Dim listpage As String = page
        Dim firstname As String
        If page.IndexOf("<div class=""singer-item singer-album"">") > 0 Then
            page = page.Substring(page.IndexOf("<div class=""first-search-song"">"), page.IndexOf("<div class=""singer-item singer-album"">") - page.IndexOf("<div class=""first-search-song"">"))
        ElseIf page.IndexOf("<div class=""singer-item singer-video"">") > 0 Then
            page = page.Substring(page.IndexOf("<div class=""first-search-song"">"), page.IndexOf("<div class=""singer-item singer-video"">") - page.IndexOf("<div class=""first-search-song"">"))
        ElseIf page.IndexOf("<div class=""content-block special-song"">") > 0 Then
            page = page.Substring(page.IndexOf("<div class=""first-search-song"">"), page.IndexOf("<div class=""content-block special-song"">") - page.IndexOf("<div class=""first-search-song"">"))
        End If
        link_timkiem = page.Substring(page.IndexOf("href"), page.IndexOf("</a>") - page.IndexOf("href"))
        link_timkiem = "http://mp3.zing.vn" + link_timkiem.Substring(6, link_timkiem.IndexOf(">") - 7)
        firstname = page.Substring(page.IndexOf("title") + 7, page.IndexOf("href") - page.IndexOf("title") - 9)
        firstname = firstname.Replace("&#039;", "").Replace("&amp;", "")

        If listpage.IndexOf("<div class=""paging"">") > 0 Then
            Dim dnfkj As String = listpage.Substring(listpage.IndexOf("<div class=""paging"">"), listpage.IndexOf("<div class=""sidebar"">") - listpage.IndexOf("<div class=""paging"">"))
            dnfkj = dnfkj.Substring(dnfkj.LastIndexOf("href") + 4, dnfkj.Length - dnfkj.LastIndexOf("href") - 4)
            dnfkj = dnfkj.Substring(2, dnfkj.IndexOf("title") - 4)
            link_result = "http://mp3.zing.vn" + dnfkj.Substring(0, dnfkj.IndexOf("p")) + "p="
            numberpage_result = Integer.Parse(dnfkj.Substring(dnfkj.IndexOf("p=") + 2, dnfkj.Length - dnfkj.IndexOf("p=") - 2))
        Else
            numberpage_result = 1
            link_result = l_search
        End If

        If _AutoPlay = True Then
            s_add_favourite = True
            LOADING(link_timkiem)
            INDEX_PLAY = 0
            TABPLAY = 0
        End If
        Application.DoEvents()

        RESULT.Clear()
        GET_LIST(1)
        indexpage_result = 1
        btnTimKiem_Click(New Object, New EventArgs)

    End Sub

    Private Sub GET_LIST(ByVal numberpage As Integer)
        Dim page As String = READ_WEB(link_result + numberpage.ToString)
        If page.IndexOf("<div class=""first-search-song"">") < 0 Then Return

        txtLoading.Text = "PAGE: " + numberpage.ToString
        Application.DoEvents()
        Dim olds As String = page
        If page.IndexOf("<div class=""singer-item singer-album"">") > 0 Then
            page = page.Substring(page.IndexOf("<div class=""first-search-song"">"), page.IndexOf("<div class=""singer-item singer-album"">") - page.IndexOf("<div class=""first-search-song"">"))
        ElseIf page.IndexOf("<div class=""singer-item singer-video"">") > 0 Then
            page = page.Substring(page.IndexOf("<div class=""first-search-song"">"), page.IndexOf("<div class=""singer-item singer-video"">") - page.IndexOf("<div class=""first-search-song"">"))
        ElseIf page.IndexOf("<div class=""content-block special-song"">") > 0 Then
            page = page.Substring(page.IndexOf("<div class=""first-search-song"">"), page.IndexOf("<div class=""content-block special-song"">") - page.IndexOf("<div class=""first-search-song"">"))
        End If
        Dim link_part1 As String = page.Substring(page.IndexOf("href"), page.IndexOf("</a>") - page.IndexOf("href"))
        link_part1 = "http://mp3.zing.vn" + link_part1.Substring(6, link_part1.IndexOf(">") - 7)
        Dim name_part1 = " " + page.Substring(page.IndexOf("title") + 7, page.IndexOf("href") - page.IndexOf("title") - 9)
        name_part1 = name_part1.Replace("&#039;", "").Replace("&amp;", "")

        RESULT.Rows.Add(link_part1, name_part1)
        sourceAutoComL.Add(name_part1)

        If olds.IndexOf("<div class=""content-block special-song"">") < 0 Then
            Return
        End If
        olds = olds.Substring(olds.IndexOf("<div class=""content-block special-song"">"), olds.IndexOf("<div class=""sidebar"">") - olds.IndexOf("<div class=""content-block special-song"">"))

        While olds.IndexOf("<h3>") >= 0
            olds = olds.Substring(olds.IndexOf("<h3>") + 4, olds.Length - olds.IndexOf("<h3>") - 4)
            Dim temp As String = olds.Substring(olds.IndexOf("<a class=""_trackLink"""), olds.IndexOf("</a>") - olds.IndexOf("<a class=""_trackLink""") + 4)
            Dim TenBaiHat As String = " " + temp.Substring(temp.IndexOf("title") + 7, temp.IndexOf("href") - temp.IndexOf("title") - 9) + Environment.NewLine
            Dim Link As String = "http://mp3.zing.vn" + temp.Substring(temp.IndexOf("href") + 6, temp.IndexOf(">") - temp.IndexOf("href") - 7) + Environment.NewLine
            TenBaiHat = TenBaiHat.Replace("&#039;", "").Replace("&amp;", "")
            RESULT.Rows.Add(Link, TenBaiHat)
            sourceAutoComL.Add(TenBaiHat.Trim)
        End While
        txtLoading.Text = "^^!"

    End Sub

    Public Shared Function READ_WEB(ByVal urls As String) As String
        Try
            Dim url As Uri = New Uri(urls)
            Dim req As WebRequest = WebRequest.Create(url)
            req.Method = "GET"
            Dim reader As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
            Return reader.ReadToEnd()
        Catch ex As Exception
            Return "".ToString
        End Try
    End Function

    Private Sub LOADING(ByVal link As String)
        txtLoading.Text = "LOADING..."
        Me.Cursor = Cursors.AppStarting
        Application.DoEvents()
        f = GET_MFILE(link)
        If f.Name = "NoName" Then
            MessageBox.Show("LINK nhạc sida, em ko tự lấy nhạc đc" + Environment.NewLine + _
                "Hoặc thuật toán tìm kiếm cùi bắp. Xin cáo lỗi :(", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Cursor = Cursors.Default
            Return
        End If
        url = f.Link
        aname = f.LinkWeb.Substring(f.LinkWeb.IndexOf("bai-hat/") + 8, f.LinkWeb.IndexOf(".html") - f.LinkWeb.IndexOf("bai-hat/") - 8)
        aname = aname.Substring(0, aname.IndexOf("/")).Replace("-", " ")
        If Not MP3 Is Nothing Then
            If MP3.Status.Trim = "playing" Then
                MP3.Stop()
                MP3.Close()
            Else
                MP3.Resume()
                MP3.Stop()
                MP3.Close()
            End If
        End If
        MP3 = New AudioFile(url)
        MP3.Play(_Repeat)
        MP3.MasterVolume = _Volume
        txtSeed_all.Text = Int(MP3.Milleseconds / 60).ToString.PadLeft(2, "0") + ":" + (MP3.Milleseconds Mod 60).ToString.PadLeft(2, "0")
        txtTitle.Text = f.Name + " - " + f.Singer
        If txtTitle.Text.Length > 36 Then
            txtTitle.Text = txtTitle.Text.Substring(0, 36) + " ..."
        End If
        btPlay.Enabled = True
        btPlay.Text = "II"
        btPrev.Enabled = True
        btNext.Enabled = True
        btDown.Enabled = True
        btLove.Enabled = True
        LLyric.Enabled = True
        s_music = True
        alenght = 0
        Lyricfrm.RichtxtLyric.Text = f.Lyric
        Me.Cursor = Cursors.Default
        txtLoading.Text = "^^!"
        If s_invi = True Then NotifyIconTray.ShowBalloonTip(5, "MMusic 3.2", f.Name + " - " + f.Singer + Environment.NewLine + "♫♪: " + txtSeed_all.Text, ToolTipIcon.Info)
        ReloadList = 10

    End Sub

    Public Sub Add_MYLIST(ByVal ll As String, ByVal nn As String)
        txtLoading.Text = "CHECK MYLIST..."
        Application.DoEvents()
        'Kiem tra lai DSDaNghe có bị trùng hay ko ?
        If s_add_favourite = True Then
            For i As Integer = 0 To MYLIST.Rows.Count - 1
                If MYLIST.Rows(i)("Link").ToString = ll Then
                    s_add_favourite = False
                    Exit For
                End If
            Next
            If s_add_favourite = True Then MYLIST.Rows.Add(ll, nn)
        End If
        txtLoading.Text = "..."
    End Sub

    Private Function GET_MFILE(ByVal link As String) As MFile
        Dim mnew As New MFile
        Dim temp As String

        'Tìm các thông tin bài hát chính 
        temp = READ_WEB(link)
        If temp <> "" Then
            Try
                mnew.Name = temp.Substring(temp.IndexOf("<h1 class=""detail-title"">") + 25, temp.IndexOf("</h1><span>") - temp.IndexOf("<h1 class=""detail-title"">") - 25)
            Catch ex As Exception
                mnew.Name = "NoName"
                Return mnew
            End Try
            'mnew.Name = temp.Substring(temp.IndexOf("<title>") + 7, temp.IndexOf("| 320") - temp.IndexOf("<title>") - 7)
            mnew.LinkWeb = link
            If temp.IndexOf("</span></span>") > 0 Then
                mnew.Lyric = temp.Substring(temp.IndexOf("</span></span>") + 14, temp.IndexOf("<p class=""seo"">") - temp.IndexOf("</span></span>") - 41).Replace("<br />", " ").Trim
            End If
            If mnew.Lyric = "" Then mnew.Lyric = Environment.NewLine + "Không có lời bài hát "

            If s_dontloadavatar = False Then
                If temp.IndexOf("singer-image") > -1 Then
                    Dim link_t As String = temp.Substring(temp.IndexOf("singer-image") + 12, temp.IndexOf("singer-site") - temp.IndexOf("singer-image"))
                    GET_IMG_SINGER(link_t)
                Else
                    pbLogo.Image = My.Resources.Resources.music
                End If
            End If

            temp = temp.Substring(temp.IndexOf("xmlURL") + 7, temp.IndexOf("textad") - temp.IndexOf("xmlURL") - 12)
        End If
        If temp.Trim = "" Then
            mnew.Name = "NoName"
            Return mnew
        End If

        'Tìm link gốc của bài hát
        temp = READ_WEB(temp)
        If temp <> "" Then
            mnew.Link = temp.Substring(temp.IndexOf("<source>") + 17, temp.IndexOf("</source>") - temp.IndexOf("<source>") - 20)
            mnew.Singer = temp.Substring(temp.IndexOf("<performer>") + 20, temp.IndexOf("</performer>") - temp.IndexOf("<performer>") - 23)
        End If
        If temp.Trim = "" Then
            mnew.Name = "NoName"
            Return mnew
        End If

        Return mnew
    End Function

    Private Sub GET_IMG_SINGER(ByVal s As String)
        If s.IndexOf("ZMEA_") > -1 Then
            s = "http://me.zing.vn/v/" + s.Substring(s.IndexOf("ZMEA_") + 5, s.IndexOf("?") - s.IndexOf("ZMEA_") - 5)
            s = READ_WEB(s)
            If s.IndexOf("avatarcoverpf") > -1 Then
                s = s.Substring(s.IndexOf("avatarcoverpf"), s.IndexOf("idcover") - s.IndexOf("avatarcoverpf"))
                s = s.Substring(s.IndexOf("url(") + 4, s.IndexOf(")") - s.IndexOf("url(") - 4)
            Else
                pbLogo.Image = My.Resources.Resources.music
                Return
            End If
        Else
            s = s.Substring(s.IndexOf("src=") + 5, s.IndexOf("alt") - s.IndexOf("src") - 7)
        End If
        pbLogo.ImageLocation = s
    End Sub

    Private Sub Betafrm_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        If Not MP3 Is Nothing Then
            MP3.Close()
        End If
        Update_ini_LIKE()
    End Sub

    Private Sub Update_ini_LIKE()
        If s_update_ini = True Then
            Dim ini As New IniFile(fconfig)
            ini.WriteValue("LIKE", "Total", MYLIST.Rows.Count.ToString)
            For i As Integer = 0 To MYLIST.Rows.Count - 1
                ini.WriteValue("LIKE", "Track" + i.ToString, MYLIST.Rows(i)("Link").ToString)
            Next
        End If
    End Sub

    Private Sub LAutoPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LAutoPlay.Click
        If _AutoPlay = True Then
            _AutoPlay = False
            LAutoPlay.Text = "N "
        Else
            _AutoPlay = True
            LAutoPlay.Text = "Y "
        End If
        Dim ini As New IniFile(fconfig)
        ini.WriteValue("PATH", "AutoPlay", _AutoPlay.ToString)
    End Sub

    Private Sub LRepeat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LRepeat.Click
        btPrev.Visible = False
        btNext.Visible = False
        Select Case _Repeat
            Case 0
                _Repeat = 1
                LRepeat.Text = "1 "
            Case 1
                _Repeat = 2
                LRepeat.Text = "A "
                btPrev.Visible = True
                btNext.Visible = True
            Case 2
                _Repeat = 3
                LRepeat.Text = "S "
                btPrev.Visible = True
                btNext.Visible = True
            Case 3
                _Repeat = 0
                LRepeat.Text = "0 "
        End Select
        Dim ini As New IniFile(fconfig)
        ini.WriteValue("PATH", "Repeat", _Repeat.ToString)
    End Sub

    Public Shared tick10 As Integer = 0
    Private Sub TimerPlay_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerPlay.Tick
        Dim END_MP3 As Boolean = False
        If Not MP3 Is Nothing Then
            If MP3.SecondPlay = MP3.Milleseconds Then
                END_MP3 = True
                Me.Text = "MMusic by MIN 3.2"
            End If
        End If

        tick10 = tick10 + 10
        If tick10 = 1000 Then tick10 = 0

        'CHUẨN 1 GIÂY
        If (tick10 Mod 1000) = 0 Then
            If ReloadList > -2 Then ReloadList -= 1
            If tempzz > 0 Then
                tempzz -= 1
                txtLoading.Text = "..."
            End If

        End If

        'CHUẨN 0.1 GIÂY
        If (tick10 Mod 100) = 0 Then
            If s_music = True Then
                alenght = MP3.SecondPlay
                txtSeed_suft.Text = Int(alenght / 60).ToString.PadLeft(2, "0") + ":" + (alenght Mod 60).ToString.PadLeft(2, "0")
                Me.Text = txtSeed_suft.Text + " " + aname
                If MP3.Milleseconds = 0 Then Seed_m_suft.Width = 0 Else Seed_m_suft.Width = alenght * Seed_m_under.Width / MP3.Milleseconds
                If MP3.Status.Trim = "stopped" Then
                    alenght = 0
                    Seed_m_suft.Width = 0
                    txtSeed_suft.Text = "00:00"
                    btPlay.Text = "► "
                    Me.Text = "MMusic by MIN 3.2"
                End If
            End If
            If s_loadmorelist = True And indexpage_result < numberpage_result Then
                indexpage_result += 1
                GET_LIST(indexpage_result)
                s_loadmorelist = False
            End If
            If Betafrm.ReloadList >= 1 Then
                If Betafrm.INDEX_PLAY > -1 And Betafrm.INDEX_PLAY <= DS.RowCount - 1 And Betafrm.tabpriate = Betafrm.TABPLAY Then
                    For i = 0 To DS.RowCount - 1
                        DS.Rows(i).Cells("Ten").Style.ForeColor = Color.FromArgb(170, 170, 170)
                        DS.Rows(i).Cells("Ten").Style.SelectionForeColor = Color.White
                    Next
                    DS.Rows(Betafrm.INDEX_PLAY).Cells("Ten").Style.ForeColor = Color.FromArgb(218, 1, 58)
                    DS.Rows(Betafrm.INDEX_PLAY).Cells("Ten").Style.SelectionForeColor = Color.FromArgb(218, 1, 58)
                    Betafrm.ReloadList = -1000
                End If
            End If
        End If
        'NOW
        If RELOAD_F = True Then
            RELOAD_F = False
            LOADING(LinkWeb)
        End If
        If s_music = True Then
            If _Repeat = 2 And END_MP3 = True And MP3.Status.Trim() = "playing" Then
                MP3.Stop()
                PlayNEXT(TABPLAY, INDEX_PLAY)
            ElseIf _Repeat = 3 And END_MP3 = True And MP3.Status.Trim() = "playing" Then
                Dim rad As New Random()
                INDEX_PLAY = rad.Next(0, DS.RowCount - 1)
                MP3.Stop()
                PlayNEXT(TABPLAY, INDEX_PLAY)
            ElseIf _Repeat = 0 And END_MP3 = True Then
                MP3.Stop()
            End If
        End If

        If s_downloading Then
            txtLoading.Text = STATUS
            tempzz = 3
        ElseIf tempzz > 0 Then
            txtLoading.Text = STATUS
        End If

    End Sub

    Private tempzz As Integer = 0

    Private Sub PlayNEXT(ByVal Tab As Integer, ByVal index As Integer)
        Dim dt As DataTable = RESULT
        Select Case TABPLAY
            Case 0
                dt = RESULT
            Case 1
                dt = MYLIST
            Case 2
                dt = BXH
            Case 3
                dt = BXH2
        End Select
        If index + 1 > dt.Rows.Count - 1 Then index = 0 Else index += 1
        LOADING(dt.Rows(index)("Link").ToString)
        INDEX_PLAY = index
    End Sub

    Private Sub btPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btPlay.Click
        If MP3.IsPaused = False Then
            If MP3.Status().Trim = "stopped" Then
                's_add_favourite = False
                'LOADING(link_timkiem)
                MP3.Close()
                MP3 = New AudioFile(url)
                MP3.Play(_Repeat)
                MP3.MasterVolume = _Volume
                s_music = True
                btPlay.Text = "II"
            Else
                MP3.Pause()
                s_music = False
                btPlay.Text = "► "
            End If
        Else
            MP3.Resume()
            s_music = True
            btPlay.Text = "II"
        End If
    End Sub

    Private Sub txtTitle_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtTitle.Click
        If f Is Nothing Then Return
        Process.Start("explorer.exe", f.LinkWeb)
    End Sub

    Private Sub Load_DSDaNghe()
        s_update_ini = False
        Dim ini As New IniFile(fconfig)

        Dim total As Integer = Integer.Parse(ini.ReadValue("LIKE", "Total"))
        If total = 0 Then
            s_update_ini = True
            Return
        End If

        For i As Integer = 0 To total - 1
            Dim mfile As MFile = GET_MFILE(ini.ReadValue("LIKE", "Track" + i.ToString))
            Betafrm.MYLIST.Rows.Add(mfile.LinkWeb, mfile.Name + " - " + mfile.Singer)
            sourceAutoComL.Add(mfile.Name)
            sourceAutoComL.Add(mfile.Singer)
        Next
        s_update_ini = True
    End Sub

    Private Sub NotifyIconTray_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotifyIconTray.Click
        If Me.WindowState = FormWindowState.Minimized Then
            Me.Show()
            Me.WindowState = FormWindowState.Normal
            Me.TopMost = True
            Me.TopMost = False
        Else
            Me.WindowState = FormWindowState.Minimized
        End If
    End Sub

    Private s_invi As Boolean = False
    Private Sub Betafrm_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize
        If Me.WindowState = FormWindowState.Minimized Then
            Me.Hide()
            If s_booltooltip = False Then
                NotifyIconTray.ShowBalloonTip(1)
                s_booltooltip = True
            End If
            s_invi = True
        Else
            s_invi = False
        End If
    End Sub

    Private Sub btPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btPrev.Click
        If _Repeat = 3 Then
            Dim rad As New Random()
            INDEX_PLAY = rad.Next(0, DS.RowCount - 1)
        End If

        Dim index As Integer = INDEX_PLAY
        Dim dt As DataTable = RESULT
        Select Case TABPLAY
            Case 0
                dt = RESULT
            Case 1
                dt = MYLIST
            Case 2
                dt = BXH
            Case 3
                dt = BXH2
        End Select
        If index - 1 < 0 Then index = dt.Rows.Count - 1 Else index -= 1
        LOADING(dt.Rows(index)("Link").ToString)
        INDEX_PLAY = index
    End Sub

    Private Sub btNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btNext.Click
        If _Repeat = 3 Then
            Dim rad As New Random()
            INDEX_PLAY = rad.Next(0, DS.RowCount - 1)
        End If

        Dim index As Integer = INDEX_PLAY
        Dim dt As DataTable = RESULT
        Select Case TABPLAY
            Case 0
                dt = RESULT
            Case 1
                dt = MYLIST
            Case 2
                dt = BXH
            Case 3
                dt = BXH2
        End Select
        If index + 1 > dt.Rows.Count - 1 Then index = 0 Else index += 1
        LOADING(dt.Rows(index)("Link").ToString)
        INDEX_PLAY = index
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Close()
    End Sub

    Private Sub btnHide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHide.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub

    Private Sub LDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Public Shared m_LyricfrmShow As Boolean = False
    Private Sub LLyric_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LLyric.Click
        If m_LyricfrmShow Then
            Lyricfrm.Close()
            m_LyricfrmShow = False
        Else
            Lyricfrm.Show()
            m_LyricfrmShow = True
        End If
    End Sub

    Private Sub l_Search_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles l_Search.MouseHover
        l_Search.BackColor = Color.FromArgb(51, 51, 51)
    End Sub

    Private Sub l_Search_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles l_Search.MouseLeave
        l_Search.BackColor = Color.FromArgb(34, 34, 34)
    End Sub

    Private Sub btnTimKiem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimKiem.Click
        DS.DataSource = Betafrm.RESULT
        Betafrm.tabpriate = 0
        If DS.RowCount = 0 Then
            Scrollbar_suft.Visible = False
            Scrollbar_under.Visible = False
        End If
        Betafrm.ReloadList = 1
        DS.ContextMenuStrip = Nothing
        btnTimKiem.ButtonActive = True
        HigthLightTab()
    End Sub

    Private Sub DS_RowsAdded(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) Handles DS.RowsAdded
        DS.Rows(e.RowIndex).Height = 25

        If DS.RowCount > 9 Then
            Scrollbar_suft.Height = 9 / DS.RowCount * Scrollbar_under.Height
            Scrollbar_suft.Visible = True
            Scrollbar_under.Visible = True
        Else
            Scrollbar_suft.Visible = False
            Scrollbar_under.Visible = False
        End If
    End Sub

    Private Sub DS_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles DS.Scroll
        Dim Scroll As Integer = Scrollbar_under.Location.Y + e.NewValue * (Scrollbar_under.Height) / (DS.RowCount)
        Scrollbar_suft.Location = New Point(Scrollbar_suft.Location.X, Scroll)
        If e.NewValue = DS.RowCount - 15 And Betafrm.tabpriate < 1 Then Betafrm.s_loadmorelist = True
    End Sub

    Private Sub DS_CellMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DS.CellMouseClick
        If DS.Columns(e.ColumnIndex).Name = "Love" Then
            s_add_favourite = True
            Add_MYLIST(DS.Rows(e.RowIndex).Cells("Link").Value, DS.Rows(e.RowIndex).Cells("Ten").Value)
        ElseIf DS.Columns(e.ColumnIndex).Name = "Download" Then
            DOWNLOADZ(DS.Rows(e.RowIndex).Cells("Link").Value)
        End If
    End Sub

    Shared fz As MFile

    Public Sub DOWNLOADZ(ByVal linkz As String)
        If _FolderSave = "" Then LabelEdit3_Click(New Object, New EventArgs)
        If _FolderSave = "" Then
            MessageBox.Show("Bạn chưa chọn thư mục lưu file nhạc", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Return
        End If
        Me.Cursor = Cursors.AppStarting
        Application.DoEvents()
        s_dontloadavatar = True
        fz = GET_MFILE(linkz)
        s_dontloadavatar = False
        If fz.Name = "NoName" Then
            MessageBox.Show("Lỗi không tìm thấy file nhạc gốc :(", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Cursor = Cursors.Default
            Return
        End If

        Dim t As New Threading.Thread(AddressOf DOWN)
        t.Start()

        Me.Cursor = Cursors.Default
    End Sub

    Public Shared s_downloading As Boolean = False

    Private Sub DOWN()
        Dim client As New WebClient
        AddHandler client.DownloadFileCompleted, AddressOf DOWN_OK
        AddHandler client.DownloadProgressChanged, AddressOf DOWN_PROCESS
        Dim anamez As String = fz.LinkWeb.Substring(fz.LinkWeb.IndexOf("bai-hat/") + 8, fz.LinkWeb.IndexOf(".html") - fz.LinkWeb.IndexOf("bai-hat/") - 8)
        anamez = anamez.Substring(0, anamez.IndexOf("/")).Replace("-", " ")
        Dim local As String = _FolderSave + "/" + anamez + ".mp3"
        Dim uri As Uri = New Uri(Betafrm.fz.Link)
        client.DownloadFileAsync(uri, local)
    End Sub
    Private Sub DOWN_OK()
        STATUS = "Download Finish."
        s_downloading = False
    End Sub

    Private Sub DOWN_PROCESS(ByVal sender As System.Object, ByVal e As DownloadProgressChangedEventArgs)
        STATUS = "Downloading " + Int(e.BytesReceived / 1024).ToString + "/" + Int(e.TotalBytesToReceive / 1024).ToString + "Kb " + e.ProgressPercentage.ToString + "% . . ."
        s_downloading = True
    End Sub

    Private Sub DS_CellMouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DS.CellMouseDown
        DS.Rows(e.RowIndex).Selected = True
    End Sub

    Private Sub ButtonA3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBXH1.Click
        If Betafrm.BXH.Rows.Count = 0 Then
            Load_BXH("http://mp3.zing.vn//bang-xep-hang/bai-hat-Viet-Nam/IWZ9Z08I.html", BXH)
        End If
        DS.DataSource = Betafrm.BXH
        Betafrm.tabpriate = 2
        If DS.RowCount = 0 Then
            Scrollbar_suft.Visible = False
            Scrollbar_under.Visible = False
        End If
        Betafrm.ReloadList = 1
        DS.ContextMenuStrip = Nothing
        HigthLightTab()
    End Sub

    Private Sub Load_BXH(ByVal li As String, ByRef bx As DataTable)
        Betafrm.BXH.Rows.Clear()
        Dim olds As String = Betafrm.READ_WEB(li)
        olds = olds.Substring(olds.IndexOf("<div class=""album-item"), olds.IndexOf("<div class=""sidebar") - olds.IndexOf("<div class=""album-item"))
        Dim i As Integer = 1

        While olds.IndexOf("<div class=""album-item"">") >= 0
            olds = olds.Substring(olds.IndexOf("<div class=""album-item"">") + 24, olds.Length - olds.IndexOf("<div class=""album-item"">") - 24)
            Dim temp As String = olds.Substring(olds.IndexOf("<a"), olds.Length - olds.IndexOf("<a"))
            Dim TenBaiHat As String = " " + temp.Substring(temp.IndexOf("title") + 7, temp.IndexOf("href") - temp.IndexOf("title") - 9).Replace("&#039;", "").Replace("&amp;", "")
            Dim Link As String = "http://mp3.zing.vn" + temp.Substring(temp.IndexOf("href") + 6, temp.IndexOf(">") - temp.IndexOf("href") - 7)
            bx.Rows.Add(Link, TenBaiHat)
            Betafrm.sourceAutoComL.Add(TenBaiHat.Trim)
            i += 1
        End While
    End Sub

    Private Sub ButtonA2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnYeuThich.Click
        DS.DataSource = Betafrm.MYLIST
        Betafrm.tabpriate = 1
        If DS.RowCount = 0 Then
            Scrollbar_suft.Visible = False
            Scrollbar_under.Visible = False
        End If
        Betafrm.ReloadList = 1
        DS.ContextMenuStrip = MenuMini
        HigthLightTab()
    End Sub

    Private Sub Scrollbar_suft_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Scrollbar_suft.MouseUp
        MouseIsDown = False
    End Sub

    Private Sub Scrollbar_suft_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Scrollbar_suft.MouseMove
        If e.Button = MouseButtons.Left Then
            If MouseIsDown = False Then
                MouseIsDown = True
                MouseIsDownLoc = New Point(e.X, e.Y)
            End If
            Dim scroll As Integer = Scrollbar_suft.Location.Y + e.Y - MouseIsDownLoc.Y
            If scroll > Scrollbar_under.Height + Scrollbar_under.Location.Y - Scrollbar_suft.Height Then
                scroll = Scrollbar_under.Height + Scrollbar_under.Location.Y - Scrollbar_suft.Height
                If Betafrm.tabpriate < 1 Then Betafrm.s_loadmorelist = True
            End If

            If scroll < Scrollbar_under.Location.Y Then scroll = Scrollbar_under.Location.Y
            Scrollbar_suft.Location = New Point(Scrollbar_suft.Location.X, scroll)
            Dim index As Integer = (Scrollbar_suft.Location.Y - Scrollbar_under.Location.Y) / (Scrollbar_under.Height) * (DS.RowCount - 1)
            DS.FirstDisplayedScrollingRowIndex = index
        End If
    End Sub

    Private Sub Scrollbar_suft_MouseHover(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Scrollbar_suft.MouseHover
        Scrollbar_suft.BackColor = Color.FromArgb(51, 51, 51)
    End Sub

    Private Sub Scrollbar_suft_MouseLeave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Scrollbar_suft.MouseLeave
        Scrollbar_suft.BackColor = Color.FromArgb(34, 34, 34)
    End Sub

    Private Sub ButtonA4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBXH2.Click
        If Betafrm.BXH2.Rows.Count = 0 Then
            Load_BXH("http://mp3.zing.vn/bang-xep-hang/bai-hat-Au-My/IWZ9Z0BW.html", BXH2)
        End If
        DS.DataSource = Betafrm.BXH2
        Betafrm.tabpriate = 3
        If DS.RowCount = 0 Then
            Scrollbar_suft.Visible = False
            Scrollbar_under.Visible = False
        End If
        Betafrm.ReloadList = 1
        DS.ContextMenuStrip = Nothing
        HigthLightTab()
    End Sub

    Private Sub HigthLightTab()
        btnTimKiem.ButtonActive = False
        btnYeuThich.ButtonActive = False
        btnBXH1.ButtonActive = False
        btnBXH2.ButtonActive = False
        btnRadio.ButtonActive = False
        Select Case tabpriate
            Case 0
                btnTimKiem.ButtonActive = True
            Case 1
                btnYeuThich.ButtonActive = True
            Case 2
                btnBXH1.ButtonActive = True
            Case 3
                btnBXH2.ButtonActive = True
            Case 4
                btnRadio.ButtonActive = True
        End Select
    End Sub

    Private Sub btnRadio_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRadio.Click


        If RADI.Rows.Count = 0 Then
            Load_RADI("http://mp3.zing.vn/xml/radio-xml/LncHTLnaVNAvGWNykFJyDHZG", RADI)
        End If
        DS.DataSource = RADI
        Betafrm.tabpriate = 4
        If DS.RowCount = 0 Then
            Scrollbar_suft.Visible = False
            Scrollbar_under.Visible = False
        End If
        Betafrm.ReloadList = 1
        DS.ContextMenuStrip = Nothing
        HigthLightTab()
    End Sub

    Private Sub Load_RADI(ByVal li As String, ByRef dt As DataTable)
        dt.Rows.Clear()
        Dim olds As String = Betafrm.READ_WEB(li)

        While olds.IndexOf("<id>") >= 0
            olds = olds.Substring(olds.IndexOf("<id>") + 4, olds.Length - olds.IndexOf("<id>") - 4)

            Dim rid As String = olds.Substring(9, olds.IndexOf("</id>") - 12)
            Dim rti As String = olds.Substring(olds.IndexOf("<title>") + 16, olds.IndexOf("</title>") - olds.IndexOf("<title>") - 19)
            Dim rsi As String = olds.Substring(olds.IndexOf("<performer>") + 20, olds.IndexOf("</performer>") - olds.IndexOf("<performer>") - 23)

            Dim link As String = "http://mp3.zing.vn/bai-hat/" + AccentRemover.UnSignVN(rti) + "-" + _
                AccentRemover.UnSignVN(rsi) + "/" + rid + ".html"
            'Dim tenbh As String = rti.Substring(rti.IndexOf("(") + 1, rti.IndexOf(")") - rti.IndexOf("(") - 1) + " - " + rsi
            Dim tenbh As String = rti + " - " + rsi
            dt.Rows.Add(link, tenbh.Trim)
        End While
    End Sub

    Private Sub NgheToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NgheToolStripMenuItem.Click
        Betafrm.s_add_favourite = False
        If DS.SelectedRows.Count = 0 Then
            Return
        End If
        Betafrm.LinkWeb = DS("Link", DS.SelectedRows(0).Index).Value
        Betafrm.RELOAD_F = True
        Betafrm.INDEX_PLAY = DS.SelectedRows(0).Index
        If Betafrm.tabpriate > -1 Then
            Betafrm.TABPLAY = Betafrm.tabpriate
        End If
    End Sub

    Private Sub XóaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XóaToolStripMenuItem.Click
        Dim li As String
        If Betafrm.f Is Nothing Then li = "" Else li = Betafrm.f.LinkWeb
        If Betafrm.TABPLAY = 1 And li = DS.SelectedRows(0).Cells("Link").Value.ToString Then
            Return
        End If
        Betafrm.MYLIST.Rows.RemoveAt(DS.SelectedRows(0).Index)
    End Sub

    Private Sub XóaTấtCảToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles XóaTấtCảToolStripMenuItem.Click
        Dim li As String
        If Betafrm.f Is Nothing Then li = "" Else li = Betafrm.f.LinkWeb
        Dim index As Integer = 0
        While index < DS.RowCount
            If Betafrm.TABPLAY = 1 And li = DS.Rows(index).Cells("Link").Value.ToString Then
                index += 1
            Else
                Betafrm.MYLIST.Rows.RemoveAt(index)
            End If
        End While
    End Sub

    Private Sub LabelEdit1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelEdit1.Click
        Aboutfrm.ShowDialog()
    End Sub


    Private Sub DS_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DS.CellDoubleClick
        If DS.SelectedRows.Count = 0 Then Return
        If DS.Columns(e.ColumnIndex).Name = "Download" Or DS.Columns(e.ColumnIndex).Name = "Love" Then Return
        Betafrm.s_add_favourite = True
        Betafrm.LinkWeb = DS("Link", DS.SelectedRows(0).Index).Value
        Betafrm.RELOAD_F = True
        Betafrm.INDEX_PLAY = DS.SelectedRows(0).Index
        If Betafrm.tabpriate > -1 Then
            Betafrm.TABPLAY = Betafrm.tabpriate
        End If
    End Sub

    Private Sub DS_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DS.RowEnter
        If DS.Rows(e.RowIndex).Cells("Ten").Style.ForeColor = Color.FromArgb(218, 1, 58) Then
            DS.Rows(e.RowIndex).Cells("Ten").Style.SelectionForeColor = Color.FromArgb(218, 1, 58)
        End If
    End Sub

    Private Sub ButtonA11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btLove.Click
        s_add_favourite = True
        Add_MYLIST(f.LinkWeb, f.Name + " - " + f.Singer)
    End Sub

    Private Sub btDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btDown.Click
        DOWNLOADZ(f.LinkWeb)
    End Sub


    Private Sub LabelEdit3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelEdit3.Click
        MessageBox.Show("Chọn thư mục lưu nhạc tải về", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Dim folder As New FolderBrowserDialog
        If folder.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim path As String = folder.SelectedPath
            If path.Substring(path.Length - 1, 1) <> "\" Then
                path += "\"
            End If
            _FolderSave = path
            Dim ini As New IniFile(Betafrm.fconfig)
            ini.WriteValue("PATH", "SaveFolder", path)
        End If
    End Sub

    Private Sub LabelEdit2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelEdit2.Click
        Process.Start("https://code.google.com/p/mmusic/")
    End Sub
End Class